package d7;

import com.jieshen.TreeNode;

import java.util.LinkedList;
import java.util.Queue;

public class offer26 {
    /**
     * 层次遍历该二叉树，交换左右孩子
     *
     * @param root
     * @return
     */
    public TreeNode mirrorTree(TreeNode root) {
        if(root==null)
            return null;
        Queue<TreeNode> queue = new LinkedList<TreeNode>();
        queue.add(root);
        while (!queue.isEmpty()){
            TreeNode node = queue.remove();
            TreeNode tmp = node.right;
            node.right = node.left;
            node.left = tmp;
            if(node.left!=null)
                queue.add(node.left);
            if(node.right!=null)
                queue.add(node.right);
        }
        return root;
    }

    public static void main(String[] args) {

    }
}
